<?php

namespace System;

class Loader {
    private $directory;

    public function setDirectory($directory) {
        $this->directory=$directory;
    }

    private function requireFile($file) {
        $pathToModule = ROOT_PATH . "/" . $this->directory . "/" . $file;
        require_once $pathToModule;
    }

    public function load() {
        $files = scandir($this->directory);

        foreach ($files as $file) {
            if (substr($file, -4) == ".php")
                self::requireFile($file);
        }
    }
}

$loader = new Loader();
$loader->setDirectory("System");
$loader->load();
$loader->setDirectory("System/Entity");
$loader->load();
$loader->setDirectory("Library");
$loader->load();